using UnityEngine;

namespace GameKitUnity.Core
{
    public static class GameKitUnityExtensions
    {
        public static T GetOrAddComponent<T>(this GameObject target) where T : MonoBehaviour
        {
            return target.TryGetComponent<T>(out var comp) ? comp : target.AddComponent<T>();
        }

        public static T GetOrAddComponent<T>(this Component target) where T : MonoBehaviour
        {
            return target.TryGetComponent<T>(out var comp) ? comp : target.gameObject.AddComponent<T>();
        }
    }
}